package com.hzit.bj1804.dianservice.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzit.bj1804.dian.entity.Memberbase;
import com.hzit.bj1804.dian.vo.MemberPage;
import com.hzit.bj1804.dianservice.dao.MemberbaseDAO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Service
public class MemberbaseServiceImpl implements  MemberbaseService {
    @Autowired
    MemberbaseDAO memberbaseDAO;

    @Override
    public PageInfo<Memberbase> seleteAllAge(@RequestParam("limit") int limit,@RequestParam("page") int page) {
        MemberPage memberPage = new MemberPage();
        memberPage.setLimit(limit);
        memberPage.setPage(page);
        PageHelper.startPage(memberPage.getPage(), memberPage.getLimit());
        List<Memberbase> list = memberbaseDAO.seleteAll();
        return new PageInfo<>(list);
    }

    @Override
    /**
     * 查询所有会员
     */
    public List<Memberbase> seleteAll() {
        return memberbaseDAO.seleteAll();
    }

    @Override
    /**
     * 根据会员名称查询会员信息
     */
    public Memberbase seleteByNmae(@RequestParam("mname")String mname) {
        return memberbaseDAO.seleteByNmae(mname);
    }

    /**
     * 根据会员名来判断密码是否正确
     * @param mname
     * @param mpassword
     * @return
     */
    @Override
    public Memberbase select(@RequestParam("mname") String mname,@RequestParam("mpassword") String mpassword) {
        return memberbaseDAO.select(mname,mpassword);
    }

    /**
     * 根据注册时间段和会员名称查询会员信息
     */
    @Override
    public List<Memberbase> seleteByTime(@RequestParam("starttime") Date starttime, @RequestParam("endtime") Date endtime, @RequestParam("") String mname) {
        return memberbaseDAO.seleteByTime(starttime,endtime,mname);
    }
    /**
     * 根据注册时间段和会员名称查询会员信息并分页
     */
    @Override
    public PageInfo<Memberbase> seleteByTimePage(@RequestParam("limit") int limit,@RequestParam("page") int page,@RequestParam("starttime") Date starttime, @RequestParam("endtime") Date endtime, @RequestParam("mname") String mname) {
        MemberPage memberPage = new MemberPage();
        memberPage.setLimit(limit);
        memberPage.setPage(page);
        PageHelper.startPage(memberPage.getPage(), memberPage.getLimit());
        List<Memberbase> list = memberbaseDAO.seleteByTime(starttime, endtime, mname);
        return new PageInfo<>(list);
    }

    /**
     * 添加会员信息
     */
    @Override
    public int insert( @RequestBody Memberbase memberbase) {
        return memberbaseDAO.insertSelective(memberbase);
    }
    /**
     * 根据ID来改变状态
     */
    @Override
    public int update(@RequestParam("mid") int mid,@RequestParam("mstatus")String mstatus) {
        return memberbaseDAO.update(mid,mstatus);
    }

    /**
     * 修改密码
     * @param mname
     * @param newmpassword
     * @return
     */
    @Override
    public int updatePassword(@RequestParam("mname") String mname,@RequestParam("newmpassword") String newmpassword) {
        return memberbaseDAO.updatePassword(mname,newmpassword);
    }

    /**
     * 根据ID来查询会员信息
     * @param mid
     * @return
     */
    @Override
    public Memberbase selectByMid(@RequestParam("mid") int mid) {
        return memberbaseDAO.selectByMid(mid);
    }


}
